home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Adobe AIR 1.5.1 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / utils / ObjectProxy.as < prev    next >
Encoding:
Text File  |  2009-02-12  |  7.8 KB  |  266 lines

  1. package mx.utils
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import flash.utils.IDataInput;
  6.    import flash.utils.IDataOutput;
  7.    import flash.utils.IExternalizable;
  8.    import flash.utils.Proxy;
  9.    import flash.utils.flash_proxy;
  10.    import flash.utils.getQualifiedClassName;
  11.    import mx.core.IPropertyChangeNotifier;
  12.    import mx.events.PropertyChangeEvent;
  13.    import mx.events.PropertyChangeEventKind;
  14.    
  15.    use namespace flash_proxy;
  16.    use namespace object_proxy;
  17.    
  18.    [Bindable("propertyChange")]
  19.    public dynamic class ObjectProxy extends Proxy implements IExternalizable, IPropertyChangeNotifier
  20.    {
  21.       private var _id:String;
  22.       
  23.       protected var notifiers:Object;
  24.       
  25.       protected var propertyList:Array;
  26.       
  27.       private var _proxyLevel:int;
  28.       
  29.       private var _type:QName;
  30.       
  31.       protected var dispatcher:EventDispatcher;
  32.       
  33.       protected var proxyClass:Class;
  34.       
  35.       private var _item:Object;
  36.       
  37.       public function ObjectProxy(param1:Object = null, param2:String = null, param3:int = -1)
  38.       {
  39.          proxyClass = ObjectProxy;
  40.          super();
  41.          if(!param1)
  42.          {
  43.             param1 = {};
  44.          }
  45.          _item = param1;
  46.          _proxyLevel = param3;
  47.          notifiers = {};
  48.          dispatcher = new EventDispatcher(this);
  49.          if(param2)
  50.          {
  51.             _id = param2;
  52.          }
  53.       }
  54.       
  55.       public function dispatchEvent(param1:Event) : Boolean
  56.       {
  57.          return dispatcher.dispatchEvent(param1);
  58.       }
  59.       
  60.       public function hasEventListener(param1:String) : Boolean
  61.       {
  62.          return dispatcher.hasEventListener(param1);
  63.       }
  64.       
  65.       override flash_proxy function setProperty(param1:*, param2:*) : void
  66.       {
  67.          var _loc4_:IPropertyChangeNotifier = null;
  68.          var _loc5_:PropertyChangeEvent = null;
  69.          var _loc3_:* = _item[param1];
  70.          if(_loc3_ !== param2)
  71.          {
  72.             _item[param1] = param2;
  73.             _loc4_ = IPropertyChangeNotifier(notifiers[param1]);
  74.             if(_loc4_)
  75.             {
  76.                _loc4_.removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE,propertyChangeHandler);
  77.                delete notifiers[param1];
  78.             }
  79.             if(dispatcher.hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
  80.             {
  81.                if(param1 is QName)
  82.                {
  83.                   param1 = QName(param1).localName;
  84.                }
  85.                _loc5_ = PropertyChangeEvent.createUpdateEvent(this,param1.toString(),_loc3_,param2);
  86.                dispatcher.dispatchEvent(_loc5_);
  87.             }
  88.          }
  89.       }
  90.       
  91.       public function willTrigger(param1:String) : Boolean
  92.       {
  93.          return dispatcher.willTrigger(param1);
  94.       }
  95.       
  96.       public function readExternal(param1:IDataInput) : void
  97.       {
  98.          var _loc2_:Object = param1.readObject();
  99.          _item = _loc2_;
  100.       }
  101.       
  102.       public function writeExternal(param1:IDataOutput) : void
  103.       {
  104.          param1.writeObject(_item);
  105.       }
  106.       
  107.       override flash_proxy function getProperty(param1:*) : *
  108.       {
  109.          var _loc2_:* = undefined;
  110.          if(notifiers[param1.toString()])
  111.          {
  112.             return notifiers[param1];
  113.          }
  114.          _loc2_ = _item[param1];
  115.          if(_loc2_)
  116.          {
  117.             if(_proxyLevel == 0 || ObjectUtil.isSimple(_loc2_))
  118.             {
  119.                return _loc2_;
  120.             }
  121.             _loc2_ = object_proxy::getComplexProperty(param1,_loc2_);
  122.          }
  123.          return _loc2_;
  124.       }
  125.       
  126.       override flash_proxy function hasProperty(param1:*) : Boolean
  127.       {
  128.          return param1 in _item;
  129.       }
  130.       
  131.       public function get uid() : String
  132.       {
  133.          if(_id === null)
  134.          {
  135.             _id = UIDUtil.createUID();
  136.          }
  137.          return _id;
  138.       }
  139.       
  140.       override flash_proxy function nextNameIndex(param1:int) : int
  141.       {
  142.          if(param1 == 0)
  143.          {
  144.             setupPropertyList();
  145.          }
  146.          if(param1 < propertyList.length)
  147.          {
  148.             return param1 + 1;
  149.          }
  150.          return 0;
  151.       }
  152.       
  153.       public function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
  154.       {
  155.          dispatcher.addEventListener(param1,param2,param3,param4,param5);
  156.       }
  157.       
  158.       override flash_proxy function nextName(param1:int) : String
  159.       {
  160.          return propertyList[param1 - 1];
  161.       }
  162.       
  163.       public function set uid(param1:String) : void
  164.       {
  165.          _id = param1;
  166.       }
  167.       
  168.       override flash_proxy function callProperty(param1:*, ... rest) : *
  169.       {
  170.          return _item[param1].apply(_item,rest);
  171.       }
  172.       
  173.       public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
  174.       {
  175.          dispatcher.removeEventListener(param1,param2,param3);
  176.       }
  177.       
  178.       protected function setupPropertyList() : void
  179.       {
  180.          var _loc1_:String = null;
  181.          if(getQualifiedClassName(_item) == "Object")
  182.          {
  183.             propertyList = [];
  184.             for(_loc1_ in _item)
  185.             {
  186.                propertyList.push(_loc1_);
  187.             }
  188.          }
  189.          else
  190.          {
  191.             propertyList = ObjectUtil.getClassInfo(_item,null,{
  192.                "includeReadOnly":true,
  193.                "uris":["*"]
  194.             }).properties;
  195.          }
  196.       }
  197.       
  198.       object_proxy function getComplexProperty(param1:*, param2:*) : *
  199.       {
  200.          if(param2 is IPropertyChangeNotifier)
  201.          {
  202.             param2.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,propertyChangeHandler);
  203.             notifiers[param1] = param2;
  204.             return param2;
  205.          }
  206.          if(getQualifiedClassName(param2) == "Object")
  207.          {
  208.             param2 = new proxyClass(_item[param1],null,_proxyLevel > 0 ? _proxyLevel - 1 : _proxyLevel);
  209.             param2.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,propertyChangeHandler);
  210.             notifiers[param1] = param2;
  211.             return param2;
  212.          }
  213.          return param2;
  214.       }
  215.       
  216.       override flash_proxy function deleteProperty(param1:*) : Boolean
  217.       {
  218.          var _loc5_:PropertyChangeEvent = null;
  219.          var _loc2_:IPropertyChangeNotifier = IPropertyChangeNotifier(notifiers[param1]);
  220.          if(_loc2_)
  221.          {
  222.             _loc2_.removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE,propertyChangeHandler);
  223.             delete notifiers[param1];
  224.          }
  225.          var _loc3_:* = _item[param1];
  226.          var _loc4_:* = delete _item[param1];
  227.          if(dispatcher.hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
  228.          {
  229.             _loc5_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE);
  230.             _loc5_.kind = PropertyChangeEventKind.DELETE;
  231.             _loc5_.property = param1;
  232.             _loc5_.oldValue = _loc3_;
  233.             _loc5_.source = this;
  234.             dispatcher.dispatchEvent(_loc5_);
  235.          }
  236.          return _loc4_;
  237.       }
  238.       
  239.       object_proxy function get type() : QName
  240.       {
  241.          return _type;
  242.       }
  243.       
  244.       object_proxy function set type(param1:QName) : void
  245.       {
  246.          _type = param1;
  247.       }
  248.       
  249.       public function propertyChangeHandler(param1:PropertyChangeEvent) : void
  250.       {
  251.          dispatcher.dispatchEvent(param1);
  252.       }
  253.       
  254.       override flash_proxy function nextValue(param1:int) : *
  255.       {
  256.          return _item[propertyList[param1 - 1]];
  257.       }
  258.       
  259.       object_proxy function get object() : Object
  260.       {
  261.          return _item;
  262.       }
  263.    }
  264. }
  265.  
  266.